
import { _decorator, Component, game, Node } from 'cc';
import { AppControll, ConfigKey, EventName, PopView, tasteMainGun_config } from '../manager/AppControll';
import { GameData } from '../system/GameData';
import { PopManager } from '../manager/PopManager';
import { SystemMessage } from './SystemMessage';
import EvtManger from '../tools/EvtManger';
import { DataHelper } from '../system/DataHelper';
import { SoundManager } from '../manager/SoundManger';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = UsingAgain
 * DateTime = Thu Jun 08 2023 17:45:31 GMT+0800 (GMT+08:00)
 * Author = guoxun
 * FileBasename = UsingAgain.ts
 * FileBasenameNoExtension = UsingAgain
 * URL = db://assets/script/pop/UsingAgain.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

@ccclass('UsingAgain')
export class UsingAgain extends Component {
    @property(Node)
    mNdArrGun: [Node] = [null];
    private mConfig: tasteMainGun_config = null;

    private isLock = false;

    protected onLoad(): void {
        GameData.isPause = true;
        this.node.getComponent("bg");
    }

    InitUsingAgain(config: tasteMainGun_config) {
        this.mConfig = config;
        let index = config.tasteId - GameData.TasteInitial;
        for (let i = 0; i < this.mNdArrGun.length; i++) {
            if (i == index) {
                this.mNdArrGun[i].active = true;
            } else {
                this.mNdArrGun[i].active = false
            }
        }
    }

    protected onDisable(): void {
        GameData.isPause = false;
    }

    OnClose() {
        AppControll.ShelvedTime = 0;
        if (this.isLock) return;
        SoundManager.Instance<SoundManager>().PlayEffect(GameData.btnClick);
        this.node.active = false;
    }

    OnConfirm() {
        AppControll.ShelvedTime = 0;
        if (this.isLock) return;
        this.isLock = true;
        SoundManager.Instance<SoundManager>().PlayEffect(GameData.btnClick);
        AppControll.Platform.ShowRewardVideoAd(this, (bool: boolean, str: string) => {
            this.isLock = false;
            if (!bool) {
                PopManager.Instance<PopManager>().ShowPop(PopView.systemMessage, (node) => {
                    node.getComponent(SystemMessage).InitContent(str);
                })
                return;
            }
            AppControll.Platform.SendBuryPoint(100013);
            let total = Number.parseInt(DataHelper.GetConfigByKey(ConfigKey.tasteGunVideoTime).value)
            EvtManger.do(EventName.tasteGun, this.mConfig, total);
            this.node.active = false;
        })

    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
